package cn.ekuma.epos.datalogic.define.dao.crm;

import java.util.List;

import cn.ekuma.data.dao.BaseDAO;
import cn.ekuma.epos.db.table.I_Customer;
import cn.ekuma.epos.db.table.crm.I_CustomerStoreValueCardDiary;

import com.openbravo.bean.crm.CustomerStoreValueCard;
import com.openbravo.bean.crm.CustomerStoreValueCardDiary;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.QBFBuilder;
import com.openbravo.data.loader.SerializerWriteBasic;
import com.openbravo.data.loader.StaticSentence;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

public class CustomerStoreValueCardDiaryDAO extends BaseDAO<CustomerStoreValueCardDiary>{

	public CustomerStoreValueCardDiaryDAO(I_Session s) {
		super(s);
	}

	@Override
	public TableDefinition getTable() {
		return new TableDefinition(s,
                "STOREVALUECARDDIARY",
                new Field[]{
                     new Field(I_CustomerStoreValueCardDiary.ID,Datas.STRING,Formats.STRING),
                     new Field(I_CustomerStoreValueCardDiary.CURDATE,Datas.TIMESTAMP,Formats.TIMESTAMP),
                     new Field(I_CustomerStoreValueCardDiary.REASON,Datas.STRING,Formats.STRING),
                     new Field(I_CustomerStoreValueCardDiary.CARDID,Datas.STRING,Formats.STRING,CustomerStoreValueCard.class),
                     new Field(I_CustomerStoreValueCardDiary.PRICE,Datas.DOUBLE,Formats.DOUBLE),
                     new Field(I_CustomerStoreValueCardDiary.USERID,Datas.STRING,Formats.STRING)
                    },
                new int[]{0});
	}

	@Override
	public void writeInsertValues(DataWrite dp, CustomerStoreValueCardDiary obj)
			throws BasicException {
		dp.setString(1,obj.getId());
		dp.setTimestamp(2,obj.getDate());
		dp.setString(3,obj.getReason());
		dp.setString(4,obj.getCardId());
		dp.setDouble(5,obj.getPrice());
		dp.setString(6,obj.getUserId());
		
	}

	@Override
	public Class getSuportClass() {
		return CustomerStoreValueCardDiary.class;
	}

	@Override
	public CustomerStoreValueCardDiary readValues(DataRead dr,
			CustomerStoreValueCardDiary obj) throws BasicException {
		if(obj==null)
			obj=new CustomerStoreValueCardDiary();
		obj.setId(dr.getString(1));
		obj.setDate(dr.getTimestamp(2));
		obj.setReason(dr.getString(3));
		obj.setCardId(dr.getString(4));
		obj.setPrice(dr.getDouble(5));
		obj.setUserId(dr.getString(6));
		return obj;
	}

	@Override
	public List<CustomerStoreValueCardDiary> list(Object filter)
			throws BasicException {
		return new StaticSentence(s, new QBFBuilder(
                this.getTableDefinition().getListSQL()+" WHERE ?(QBF_FILTER) "
                + "ORDER BY CURDATE DESC", new String[]{I_CustomerStoreValueCardDiary.CURDATE, I_CustomerStoreValueCardDiary.CURDATE, I_CustomerStoreValueCardDiary.CARDID}), new SerializerWriteBasic(new Datas[]{Datas.OBJECT, Datas.TIMESTAMP, Datas.OBJECT, Datas.TIMESTAMP, Datas.OBJECT, Datas.STRING}), this).list(filter);

	}
	
	
	

}
